<template>
  <div class="app-container">
        <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
         <el-input v-model="searchObj.courseTitle" placeholder="课程标题"/>
      </el-form-item>
      <el-form-item>
         <el-input v-model="searchObj.teacherName" placeholder="讲师名称"/>
      </el-form-item>
      <el-form-item>
         <el-input v-model="searchObj.nickname" placeholder="用户昵称"/>
      </el-form-item>
      
      <el-form-item>
        <el-date-picker
          v-model="searchObj.begin"
          type="date"
          placeholder="选择开始日期"
          value-format="yyyy-MM-dd" />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="searchObj.end"
          type="date"
          placeholder="选择截止日期"
          value-format="yyyy-MM-dd" />
      </el-form-item>

      <el-button type="primary" icon="el-icon-search" @click="fetchData()">订单查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>


    <!-- banner列表 -->
    <el-table
      :data="list"
      stripe
      style="width: 100%"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="courseTitle" label="课程标题" width="150" />
      <el-table-column
        header-align="center"
        align="center"
        label="课程封面"
      >
        <template slot-scope="scope">
          <img :src="scope.row.courseCover" style="width: 70px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column prop="teacherName" label="讲师名称" width="180" />
      <el-table-column prop="nickname" label="用户昵称" width="180" />
      <el-table-column prop="mobile" label="用户电话" width="180" />
      <el-table-column prop="totalFee" label="订单金额" width="180" >
        <template slot-scope="scope">
          <p>{{scope.row.totalFee}} 元</p>
        </template>
      </el-table-column>
      <el-table-column prop="payType" label="支付方式" width="180">
        <template slot-scope="scope">
          <el-tag
          disable-transitions
          >{{scope.row.payType === 1 ? '微信':'支付宝'}}
          </el-tag>
        </template>
        </el-table-column>
      <el-table-column prop="status" label="支付状态" width="180">
        <template slot-scope="scope">
          <el-tag
          :type="scope.row.status === 1 ? 'success' : 'danger'"
          disable-transitions
          >{{scope.row.status === 1 ? '已支付':'未支付'}}
          </el-tag>
        </template>
        </el-table-column>
      <el-table-column prop="gmtCreate" label="创建时间" width="180" />
    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="fetchData"
      @size-change="changeSize"
    />
  </div>
</template>

<script>
import order from "@/api/order/order";

const defaultForm = {
  title: "",
  imageUrl: "",
  linkUrl: "",
};

export default {
  data() {
    return {
      list: [], // 订单列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      searchObj: {}, // 查询表单对象
    };
  },

  created() {
    console.log("list created......");
    this.fetchData();
  },

  mounted() {
    console.log("list mounted......");
  },

  methods: {

    // 当页码发生改变的时候
    changeSize(size) {
      console.log(size);
      this.limit = size;
      this.fetchData(1);
    },

    // 加载讲师列表数据
    fetchData(page = 1) {
      console.log("翻页。。。" + page);
      // 异步获取远程数据（ajax）
      this.page = page;

      order.getPageList(this.page, this.limit, this.searchObj).then((response) => {
        this.list = response.data.items;
        this.total = response.data.total;
      });
    },

    // 重置查询表单
    resetData() {
      console.log("重置查询表单");
      this.searchObj = {};
      this.fetchData();
    },

    // 执行搜索
    // queryString：文本框中输入的值
    // cb：一个函数
    querySearch(queryString, cb) {
      console.log(queryString);
      console.log(cb);
    },
  },
};
</script>

